from __future__ import unicode_literals

import time

from django.db import models

year = (time.strftime("%y"))
month = (time.strftime("%m"))
date = (time.strftime("%d"))


class Base(models.Model):
    def get_my_img(self):
        return 'img_' + self.__class__.__name__.lower()

    def set_my_img(self, temp_img):
        self.__dict__[self.get_my_img()] = temp_img

    def get_img_id(self):
        return str(self.__dict__[self.__class__.__name__.lower() + 'Id'])

    class Meta:
        abstract = True


# 用户表
class User(models.Model):
    userId = models.AutoField(primary_key=True, verbose_name="用户ID", null=False, unique=True)
    username = models.CharField(max_length=50, verbose_name='用户名', unique=True)  # 添加label标签
    password = models.CharField(max_length=50, verbose_name='密码')
    name = models.CharField(max_length=50, verbose_name='昵称')
    phone = models.CharField(max_length=50, verbose_name="手机号")
    # 管理类型 默认root 中级权限middle 普通权限ordinary
    admin_type = models.CharField(max_length=20, verbose_name="管理类型", default="ordinary")
    position = models.CharField(max_length=50, verbose_name="职位")
    # 头像 文件路径 参数：文件路径 文件名 recursive是否包含子目录路径
    headImg = models.ImageField(upload_to="users", max_length=100, verbose_name="用户头像", default='users/default.png')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return str(self.userId)


# 外聘表
class Employee(Base):
    employeeId = models.AutoField(primary_key=True, verbose_name="外聘ID", null=False, unique=True)
    name_employee = models.CharField(max_length=50, verbose_name='外聘名')
    # 雇员类型：摄影师、跟拍师、跟状师、化妆师、婚礼司仪等人员。
    type_employee = models.CharField(max_length=50, verbose_name="外聘类型")
    # 价格
    prize_employee = models.IntegerField(verbose_name="价格")
    phone_employee = models.CharField(max_length=11, verbose_name="联系电话")
    note_employee = models.TextField(verbose_name='备注', default="无")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)
    img_index = models.ImageField(upload_to="employeeRes", max_length=100, verbose_name="外聘主页照片",
                                  default='default.png')
    img_employee = models.CharField(max_length=200, verbose_name="宣传图")  # 若启用备用方案请注意本条
    video_employee = models.FileField(upload_to="employeeRes", verbose_name="宣传视频", null=True)


# 酒店表
class Hotel(Base):
    hotelId = models.AutoField(primary_key=True, verbose_name="酒店编号", null=False, unique=True)
    name_hotel = models.CharField(max_length=100, verbose_name="酒店名")
    phone_hotel = models.CharField(max_length=11, verbose_name="联系电话")
    img_index = models.ImageField(upload_to="hotelRes", max_length=100, verbose_name="主页照片",
                                  default='default.png')
    # ppt
    ppt = models.FileField(upload_to="hotelRes", verbose_name="PPT")
    # 备注
    note_hotel = models.TextField(default="无", verbose_name="备注")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)


# 优秀案例
class Case(Base):
    caseId = models.AutoField(primary_key=True, verbose_name="案例编号", null=False, unique=True)
    name_case = models.CharField(max_length=100, verbose_name="案例名")
    # 宣传图和宣传视频
    img_case = models.CharField(max_length=200, verbose_name="宣传图")  # 若启用备用方案请注意本条
    # 备注
    note_case = models.TextField(default="无", verbose_name="备注")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)


# 婚庆公司表
class Company(Base):
    companyId = models.AutoField(primary_key=True, verbose_name="公司表编号", null=False, unique=True)
    name_company = models.CharField(max_length=100, verbose_name="公司名")
    user_company = models.CharField(max_length=100, verbose_name="公司实际管理员")
    phone_company = models.CharField(max_length=11, verbose_name="联系电话")
    # 公司简介
    info_company = models.TextField(verbose_name="公司简介")
    # 宣传图和宣传视频
    img_index = models.ImageField(upload_to="companyRes", max_length=100, verbose_name="主页照片",
                                  default='default.png')
    # img = models.ImageField(upload_to="companyRes", max_length=100, verbose_name="公司宣传图", default='default.png')
    img_company = models.CharField(max_length=200, verbose_name="宣传图")  # 若启用备用方案请注意本条
    video_company = models.FileField(upload_to="companyRes", verbose_name="宣传视频")
    # 备注
    note_company = models.TextField(default="无", verbose_name="备注")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)


# def user_directory_path(instance, filename):
#     return '{0}/{1}'.format(instance.resource_type, filename)
#
#
# class MediaStorages(models.Model):
#     storagesId = models.AutoField(primary_key=True, verbose_name="存储编号", null=False, unique=True)
#     img = models.ImageField(upload_to=user_directory_path, max_length=100)
#     # resource_type
#     resource_type = models.CharField(max_length=10, verbose_name="来源")
#     resource_type_id = models.CharField(max_length=100, verbose_name="来源id")

# 订单管理表
class OrderManager(models.Model):
    orderId = models.AutoField(primary_key=True, verbose_name="订单编号", null=False, unique=True)
    # 员工编号
    userId = models.ForeignKey(to=User, to_field="userId", on_delete=models.CASCADE, verbose_name="员工编号")
    marryTime = models.CharField(max_length=50, verbose_name='婚宴时间', default="0")
    phone = models.CharField(max_length=11, verbose_name="员工电话")
    customer = models.CharField(max_length=10, verbose_name="客户名")
    c_phone = models.CharField(max_length=11, verbose_name="客户电话")
    c_other = models.CharField(max_length=11, verbose_name="其他联系方式")
    prize = models.IntegerField(verbose_name="价格")
    # 订单状态：已完成、已取消、已中止、已付款、未付款、已退款、需跟进、未核实
    status = models.CharField(max_length=10, verbose_name="订单状态")
    # 备注
    note = models.TextField(default="无", verbose_name="备注")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return str(self.orderId)


# 订单
class Order(models.Model):
    # 订单编号
    orderId = models.OneToOneField(to=OrderManager, to_field="orderId", on_delete=models.CASCADE, verbose_name="订单编号")
    userId = models.ForeignKey(to=User, to_field="userId", on_delete=models.CASCADE, verbose_name="员工编号")
    marryTime = models.CharField(max_length=50, verbose_name='婚宴时间', default="0")
    # 婚宴地点
    marryPlace = models.TextField(default=1, verbose_name='婚宴地点')
    # 新郎新娘信息
    Bridegroom_name = models.CharField(max_length=50, verbose_name='新郎名', default="0")
    Bridegroom_phone = models.CharField(max_length=50, verbose_name='新郎电话', default="0")
    Bridegroom_address = models.CharField(max_length=50, verbose_name='新郎地址', default="0")
    Bride_name = models.CharField(max_length=50, verbose_name='新娘名', default="0")
    Bride_phone = models.CharField(max_length=50, verbose_name='新娘电话', default="0")
    Bride_address = models.CharField(max_length=50, verbose_name='新娘地址', default="0")

    host_employeeId = models.CharField(max_length=50, verbose_name='主持', default="0")
    cameraman_employeeId = models.CharField(max_length=50, verbose_name='摄像', default="0")
    photographer_employeeId = models.CharField(max_length=50, verbose_name='摄影', default="0")
    dresser_employeeId = models.CharField(max_length=50, verbose_name='化妆', default="0")
    ushers_employeeId = models.CharField(max_length=50, verbose_name='傧相', default="0")
    full_dress_companyId = models.CharField(max_length=50, verbose_name='礼服', default="0")
    wedding_gift_companyId = models.CharField(max_length=50, verbose_name='喜礼', default="0")
    motorcade_companyId = models.CharField(max_length=50, verbose_name='车队', default="0")
    wedding_companyId = models.CharField(max_length=50, verbose_name='婚庆', default="0")
    # 管家类型
    type = models.CharField(max_length=50, verbose_name="管家类型", default="全程管家")
    channel = models.CharField(max_length=50, verbose_name="渠道", default="无", )
    # 员工编号
    assignment = models.TextField(verbose_name="人员分配", default="无")
    process = models.TextField(verbose_name="流程表", default="无")
    # situation = models.TextField(verbose_name="沟通情况", default="无")
    rehearsal = models.TextField(verbose_name="彩排", default="无")
    # 备注
    note = models.TextField(default="无", verbose_name="备注")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)


# 公共消息管理表
class AllMessageM(models.Model):
    # 消息编号
    messageId = models.AutoField(primary_key=True, verbose_name="员工编号")
    # 订单编号
    orderId = models.OneToOneField(to=Order, to_field="orderId", on_delete=models.CASCADE, verbose_name="订单编号")
    # 员工编号
    userId = models.ForeignKey(to=User, to_field="userId", on_delete=models.CASCADE, verbose_name="员工编号")
    # 消息详情,任务详情
    detail = models.JSONField(null=True)
    # 订单状态：完成、未完成、改期
    status = models.CharField(max_length=10, verbose_name="订单状态")
    # 备注
    note = models.TextField(default="无")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)


# 个人消息管理表
class MyMessageM(models.Model):
    orderId = models.ForeignKey(to=Order, to_field="orderId", on_delete=models.CASCADE, verbose_name="订单编号")
    # 消息编号
    messageId = models.AutoField(primary_key=True, verbose_name="员工编号")
    # 消息详情
    detail = models.JSONField(null=True, verbose_name='消息详情')
    # 订单状态：完成、未完成、改期
    status = models.CharField(max_length=10, verbose_name="订单状态")
    # 预计时间
    expect_time = models.CharField(max_length=50, verbose_name="预计时间", default=year + 'y' + month + 'm' + date)
    # 备注
    note = models.TextField(default="无", verbose_name="备注")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)


# 问题提交表
class QuestionSubmission(models.Model):
    # 用户编号
    questionId = models.AutoField(primary_key=True, verbose_name="问题编号")
    # userId = models.ForeignKey(to=User, to_field="userId", on_delete=models.CASCADE, verbose_name="员工编号")
    question = models.TextField(verbose_name="问题")
    username = models.CharField(max_length=50)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True)